Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix slow database queries, by using partial index idx_torrentstate__last_check__partial #7955

Merged
merged 1 commit into from
Apr 5, 2024

Conversation

kozlovsky
Copy link
Contributor

@kozlovsky kozlovsky commented Apr 4, 2024

This PR fixes #7954 by adding the exact SQL condition has_data = 1 to queries to the TorrentState table.
It allows SQLite query optimizer to use a partial index on TorrentState table, defined as

    CREATE INDEX IF NOT EXISTS idx_torrentstate__last_check__partial
    ON TorrentState (last_check, seeders, leechers, self_checked)
    WHERE has_data = 1;

As a result, the speed of queries issued by the torrent checker icreases drastically, from 4 seconds to 0.04 seconds.

@kozlovsky kozlovsky requested review from a team and xoriole and removed request for a team April 4, 2024 07:10
@kozlovsky kozlovsky changed the base branch from main to release/7.13 April 4, 2024 07:51
@kozlovsky kozlovsky changed the base branch from release/7.13 to release/7.14 April 5, 2024 11:11
@kozlovsky kozlovsky merged commit 023f44d into Tribler:release/7.14 Apr 5, 2024
17 checks passed
@kozlovsky kozlovsky deleted the fix/slow_queries branch April 5, 2024 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

[7.13.3] Some database queries can be very slow
2 participants